package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Article;
import com.miku.blog.domain.param.ReceptionParam;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.vo.ArticleEditVo;
import com.miku.blog.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author shkstart
 * @create ${}YEAR-05-27 3:06
 */
@Api(tags = "后台管理系统[文章]")
@RequestMapping("/admin")
@RestController
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @SystemLog(notes = "查询文章列表{后台管理系统}")
    @ApiOperation(value = "查询文章列表接口",notes = "分页查询文章列表(根据搜索内容，及是否已删除/是否是草稿)")
    @GetMapping("/articles")
    public ResponseResult articles(@RequestParam("current") Integer current,
                                   @RequestParam("size") Integer size,
                                   @RequestParam(value = "keywords",required = false) String keywords,
                                   @RequestParam(value = "isDelete",required = false) Integer isDelete,
                                   @RequestParam(value = "status",required = false) Integer status,
                                   @RequestParam(value = "type",required = false) Integer type,
                                   @RequestParam(value = "categoryId",required = false) Integer categoryId,
                                   @RequestParam(value = "tagId",required = false) Integer tagId
    ){
        return articleService.articles(current, size,keywords,isDelete,status,type,categoryId,tagId);
    }


    @SystemLog(notes = "编辑文章{后台管理系统}")
    @ApiOperation(value = "编辑文章接口",notes = "根据文章ID,获取编辑所需内容")
    @GetMapping("/articles/{articleId}")
    public ResponseResult editArticle(@PathVariable("articleId") Integer articleId){
        return articleService.editArticle(articleId);
    }


    @SystemLog(notes = "删除文章(非真正删除){后台管理系统}")
    @ApiOperation(value = "删除文章(非真正删除)接口",notes = "删除指定文章列表 {非物理上删除}")
    @PutMapping("/articles")
    public ResponseResult deleteArticleByLogic(@RequestBody ReceptionParam receptionParam){
        return articleService.deleteArticleByLogic(receptionParam);
    }


    @SystemLog(notes = "删除文章(物理删除){后台管理系统}")
    @ApiOperation(value = "删除文章接口",notes = "删除指定文章列表 {物理上删除 (真正删除)}")
    @DeleteMapping("/articles")
    public ResponseResult deleteArticle(@RequestBody Integer[] articleIdList){
        return articleService.deleteArticle(articleIdList);
    }


    @SystemLog(notes = "添加或修改文章{后台管理系统}")
    @ApiOperation(value = "添加或修改文章接口",notes = "保存指定文章")
    @PostMapping("/articles")
    public ResponseResult saveArticle(@RequestBody ArticleEditVo articleEditVo){
        return  articleService.saveArticle(articleEditVo);
    }

    @SystemLog(notes = "文章置顶{后台管理系统}")
    @ApiOperation(value = "文章置顶接口",notes = "根据文章ID修改文章置顶状态")
    @PutMapping("/articles/top")
    public ResponseResult top(@RequestBody Article article){
        return articleService.top(article);
    }



}
